package com.adtech.adms.commons.web.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.TextField;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * @author Dormin 
 * @since 2011-5-17 
 * 
 * @Copyright (C) AD Tech Workshop All Right Reserved
 */
public class FilterText extends TextField {
	public String getExptype() {
		return exptype;
	}

	public void setExptype(String exptype) {
		this.exptype = exptype;
	}

	public String getFormatter() {
		return formatter;
	}

	public void setFormatter(String formatter) {
		this.formatter = formatter;
	}

	protected String exptype;
	protected String formatter;

	protected Boolean hidden;
	protected String perfix;

	public Boolean getHidden() {
		return hidden;
	}
	protected String filterItemName;
	public String getFilterItemName() {
		return filterItemName;
	}

	public void setFilterItemName(String filterItemName) {
		this.filterItemName = filterItemName;
	}

	public void setHidden(Boolean hidden) {
		this.hidden = hidden;
	}

	public String getPerfix() {
		if (perfix == null || "".equals(perfix)) {
			return DEF_PERFIX;
		}
		return perfix;
	}

	public void setPerfix(String perfix) {
		this.perfix = perfix;
	}

	private static final String DEF_TEMP = "filtertext";
	private static final String DEF_PERFIX = "filterMap";

	public FilterText(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack, request, response);
	}

	@Override
	protected String getDefaultTemplate() {
		return DEF_TEMP;
	}

	@Override
	public void evaluateParams() {
		super.evaluateParams();
		if (exptype != null) {
			addParameter("exptypeName", getPerfix() + "['" + name
					+ "'].expType");
			addParameter("exptype", findValue(exptype, String.class));
		}
		if (formatter != null) {
			addParameter("formatterName", getPerfix() + "['" + name
					+ "'].formatter");
			addParameter("formatter", findValue(formatter, String.class));
		}
		addParameter("name", getPerfix() + "['" + name + "'].filterValue");
		addParameter("filterName", getPerfix() + "['" + name + "'].filterName");
		if(filterItemName!=null&&!"".equals(filterItemName)){
			addParameter("filterNameValue",filterItemName);
		}else{
			addParameter("filterNameValue",name);
		}
		String expr = completeExpressionIfAltSyntax(getPerfix() + "['" + name + "'].filterValue");
		addParameter("nameValue", findValue(expr, String.class));
		addParameter("hidden", hidden);


	}
}
